package com.example.AoUserApp.controller;


import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.scene.Node;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import java.text.DecimalFormat;
import java.util.ArrayList;

/**
 * 主页面XMl对应的Controller
 */
public class HelloController {

    public static ArrayList arrayList = new ArrayList();

    @FXML
    private Button usbBT;
    @FXML
    private Button rs485BT;
    @FXML
    private Button ethernetBT;
    @FXML
    private Label powerLBW;
    @FXML
    private Label powerLBmW;
    @FXML
    private Label powerLBdBm;


    @FXML
    protected void onRs485BTClick() {
        usbBT.setStyle("-fx-background-color: rgb(47,85,151)");
        rs485BT.setStyle("-fx-background-color:  rgb(143,170,220)");
        ethernetBT.setStyle("-fx-background-color:  rgb(47,85,151)");
        arrayList.add(rs485BT);
    }

    @FXML
    protected void onEthernetBTClick() {
        usbBT.setStyle("-fx-background-color: rgb(47,85,151)");
        rs485BT.setStyle("-fx-background-color:  rgb(47,85,151)");
        ethernetBT.setStyle("-fx-background-color:  rgb(143,170,220)");
        arrayList.add(ethernetBT);
    }
    @FXML
    private HBox sprHB;

    DecimalFormat decimalFormat = new DecimalFormat("#.00");
    @FXML
    protected void onPowerLBWClick() {
        ObservableList<Node> children = sprHB.getChildren();
        Double v = Double.parseDouble(powerTF.getText());
        for (Node child : children) {
            String style = child.getStyle();
            if (style.equals("-fx-background-color: rgb(16, 253, 16)")){
                Label child1 = (Label) child;
                switch (child1.getText().toUpperCase()) {
                    case "W":break;
                    case "MW":Double v1 = v / 1000;powerTF.setText(decimalFormat.format(v1));powerSd.setMax(20);powerSd.setValue(v1);break;
                    case "DBM":Double v2 = Math.pow(10,v/10)/1000;powerTF.setText(decimalFormat.format(v2));powerSd.setValue(v2);powerSd.setMax(20);
                }
            }
        }
        powerLBW.setStyle("-fx-background-color: rgb(16, 253, 16)");
        powerLBmW.setStyle("-fx-background-color: rgb(255, 255, 255)");
        powerLBdBm.setStyle("-fx-background-color: rgb(255, 255, 255)");
    }

    @FXML
    protected void onpowerLBmWClick() {
        ObservableList<Node> children = sprHB.getChildren();
        Double v = Double.parseDouble(powerTF.getText());
        for (Node child : children) {
            String style = child.getStyle();
            if (style.equals("-fx-background-color: rgb(16, 253, 16)")){
                Label child1 = (Label) child;
                switch (child1.getText().toUpperCase()) {
                    case "W":Double v1 = v * 1000;powerTF.setText(decimalFormat.format(v1));powerSd.setMax(20*1000);powerSd.setValue(v1);break;
                    case "MW": break;
                    case "DBM":Double v2 = Math.pow(10,v/10);powerTF.setText(decimalFormat.format(v2));powerSd.setMax(20*1000);powerSd.setValue(v2);break;
                }
            }
        }
        powerLBW.setStyle("-fx-background-color: rgb(255, 255, 255)");
        powerLBmW.setStyle("-fx-background-color: rgb(16, 253, 16)");
        powerLBdBm.setStyle("-fx-background-color: rgb(255, 255, 255)");

    }

    @FXML
    protected void onpowerLBdBmClick() {ObservableList<Node> children = sprHB.getChildren();
        Double v = Double.parseDouble(powerTF.getText());
        for (Node child : children) {
            String style = child.getStyle();
            if (style.equals("-fx-background-color: rgb(16, 253, 16)")){
                Label child1 = (Label) child;
                switch (child1.getText().toUpperCase()) {
                    case "W": Double v2 = v*1000; v2 = 10*Math.log10(v2);powerTF.setText(decimalFormat.format(v2));powerSd.setMax(10*Math.log10(20*1000));powerSd.setValue(v2);break;
                    case "MW": Double v1 = 10*Math.log10(v);powerTF.setText(decimalFormat.format(v1));powerSd.setMax(10*Math.log10(20*1000));powerSd.setValue(v1);break;
                    case "DBM":
                }
            }
        }
        powerLBW.setStyle("-fx-background-color: rgb(255, 255, 255)");
        powerLBmW.setStyle("-fx-background-color: rgb(255, 255, 255)");
        powerLBdBm.setStyle("-fx-background-color: rgb(16, 253, 16)");
    }

    @FXML
    private Label prrLBHz;
    @FXML
    private Label prrLBKHz;
    @FXML
    private Label prrLBMHz;
    @FXML
    private HBox sprrHB;
    @FXML
    protected void onprrLBHzClick() {
        ObservableList<Node> children = sprrHB.getChildren();
        Double v = Double.parseDouble(prrTF.getText());
        for (Node child : children) {
            String style = child.getStyle();
            if (style.equals("-fx-background-color: rgb(16, 253, 16)")){
                Label child1 = (Label) child;
                switch (child1.getText().toUpperCase()) {
                    case "HZ":break;
                    case "KHZ":Double v1 = v*1000;prrTF.setText(v1.toString());break;
                    case "MHZ":Double v2 = v*1000000;prrTF.setText(v2.toString());break;
                }
            }
        }
        prrLBHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBKHz.setStyle("-fx-background-color: rgb(255, 255, 255)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255, 255, 255)");
    }

    @FXML
    protected void onprrLBKHzClick() {
        ObservableList<Node> children = sprrHB.getChildren();
        Double v = Double.parseDouble(prrTF.getText());
        for (Node child : children) {
            String style = child.getStyle();
            if (style.equals("-fx-background-color: rgb(16, 253, 16)")){
                Label child1 = (Label) child;
                switch (child1.getText().toUpperCase()) {
                    case "HZ":Double v1 = v/1000;prrTF.setText(v1.toString());break;
                    case "KHZ":break;
                    case "MHZ":Double v2 = v*1000;prrTF.setText(v2.toString());break;
                }
            }
        }
        prrLBHz.setStyle("-fx-background-color: rgb(255, 255, 255)");
        prrLBKHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255, 255, 255)");
    }

    @FXML
    protected void onprrLBMHzClick() {
        ObservableList<Node> children = sprrHB.getChildren();
        Double v = Double.parseDouble(prrTF.getText());
        for (Node child : children) {
            String style = child.getStyle();
            if (style.equals("-fx-background-color: rgb(16, 253, 16)")){
                Label child1 = (Label) child;
                switch (child1.getText().toUpperCase()) {
                    case "HZ":Double v1 = v/1000000;prrTF.setText(v1.toString());break;
                    case "KHZ":Double v2 = v/1000;prrTF.setText(v2.toString());break;
                    case "MHZ":break;
                }
            }
        }
        prrLBHz.setStyle("-fx-background-color: rgb(255, 255, 255)");
        prrLBKHz.setStyle("-fx-background-color: rgb(255, 255, 255)");
        prrLBMHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
    }

    @FXML
    private Label singleLB10Hz;
    @FXML
    private Label singleLB100Hz;
    @FXML
    private Label singleLB1KHz;
    @FXML
    private Label singleLB10KHz;
    @FXML
    private Label singleLB100KHz;
    @FXML
    private Label singleLB1MHz;
    @FXML
    private TextField prrTF;

    @FXML
    protected void onsingleLB10HzClick() {
        singleLB10Hz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        singleLB100Hz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB1KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB10KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB1MHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        prrTF.setText("10");
        prrLBHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBKHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255,255,255)");
    }

    @FXML
    protected void onsingleLB100HzClick() {
        singleLB10Hz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100Hz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        singleLB1KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB10KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB1MHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        prrTF.setText("100");
        prrLBHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBKHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255,255,255)");
    }

    @FXML
    protected void onsingleLB1KHzClick() {
        singleLB10Hz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100Hz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB1KHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        singleLB10KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB1MHz.setStyle("-fx-background-color: rgb(208,206,206)");
        prrTF.setText("1");
        prrLBHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBKHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255,255,255)");
    }

    @FXML
    protected void onsingleLB10KHzClick() {
        singleLB10Hz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100Hz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB1KHz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB10KHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        singleLB100KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB1MHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        prrTF.setText("10");
        prrLBHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBKHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255,255,255)");
    }

    @FXML
    protected void onsingleLB100KHzClick() {
        singleLB10Hz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB100Hz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB1KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB10KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB100KHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        singleLB1MHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        prrTF.setText("100");
        prrLBHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBKHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrLBMHz.setStyle("-fx-background-color: rgb(255,255,255)");
    }

    @FXML
    protected void onsingleLB1MHzClick() {
        singleLB10Hz.setStyle("-fx-background-color: rgb(208,206,206)");
        singleLB100Hz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB1KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB10KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB100KHz.setStyle("-fx-background-color:  rgb(208,206,206)");
        singleLB1MHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
        prrTF.setText("1");
        prrLBHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBKHz.setStyle("-fx-background-color: rgb(255,255,255)");
        prrLBMHz.setStyle("-fx-background-color: rgb(16, 253, 16)");
    }

    @FXML
    private Label pulseFsLB;
    @FXML
    private Label pulsePsLB;

    @FXML
    protected void onpulseFsLBClick() {
        pulseFsLB.setStyle("-fx-background-color: rgb(16, 253, 16)");
        pulsePsLB.setStyle("-fx-background-color: rgb(255,255,255)");
    }

    @FXML
    protected void onpulsePsLBClick() {
        pulseFsLB.setStyle("-fx-background-color: rgb(255, 255, 255)");
        pulsePsLB.setStyle("-fx-background-color: rgb(16, 253, 16)");
    }

    @FXML
    private Slider powerSd;
    @FXML
    private Slider pulseSd;
    @FXML
    private TextField powerTF;
    @FXML
    private TextField pulseTF;

    @FXML
    protected void powerTFChangeText() {
        String text = powerTF.getText();
        Double i = Double.parseDouble(text);
        powerSd.setValue(i);
    }

    @FXML
    protected void pulseTFChangeText() {
        String text = pulseTF.getText();
        Double i = Double.parseDouble(text);
        pulseSd.setValue(i);
    }

    @FXML
    protected void powerSdListen() {
        Integer value = (int) powerSd.getValue();
        powerTF.setText(value.toString());
    }

    @FXML
    protected void pulseSdListen() {
        Integer value = (int) pulseSd.getValue();
        pulseTF.setText(value.toString());
    }

    @FXML
    private Button stopBT;

    @FXML
    protected void onStopBTPressed() {
        stopBT.setStyle("-fx-background-color: rgb(143,170,220)");
    }

    @FXML
    protected void onStopBTReleased() {
        stopBT.setStyle("-fx-background-color:  rgb(48,117,178)");
    }

    @FXML
    private Button set1;
    @FXML
    private Button set2;
    @FXML
    private Button set3;
    @FXML
    private Label SPrLB;

    @FXML
    protected void onSet1Pressed() {
        set1.setStyle("-fx-background-color: rgb(143,170,220)");
    }

    @FXML
    protected void onSet1Released() {
        set1.setStyle("-fx-background-color:  rgb(48,117,178)");
    }

    @FXML
    protected void onSet2Pressed() {
        set2.setStyle("-fx-background-color: rgb(143,170,220)");
    }

    @FXML
    protected void onSet2Released() {
        set2.setStyle("-fx-background-color:  rgb(48,117,178)");
    }

    @FXML
    protected void onSet3Pressed() {
        set3.setStyle("-fx-background-color: rgb(143,170,220)");
    }

    @FXML
    protected void onSet3Released() {
        set3.setStyle("-fx-background-color:  rgb(48,117,178)");
    }

    @FXML
    private Button LOADBT;
    @FXML
    private Button SAVEBT;

    @FXML
    protected void onLOADBTPressed() {
        LOADBT.setStyle("-fx-background-color: rgb(143,170,220)");
    }

    @FXML
    protected void onLOADBTReleased() {
        LOADBT.setStyle("-fx-background-color: rgb(47,85,151)");
    }

    @FXML
    protected void onSAVEBTPressed() {
        SAVEBT.setStyle("-fx-background-color: rgb(143,170,220)");
    }

    @FXML
    protected void onSAVEBTReleased() {
        SAVEBT.setStyle("-fx-background-color:   rgb(47,85,151)");
    }



}